<template>
  <div class="login">
    <div class="login-wrap">
      <h1>登录</h1>
      <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="50px" class="demo-ruleForm">
        <el-form-item label="账号" prop="checkAccount">
          <el-input v-model="ruleForm2.checkAccount" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input type="password" v-model="ruleForm2.pass" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm2')">提交</el-button>
          <el-button @click="resetForm('ruleForm2')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入账号'))
      } else {
        callback()
      }
    }
    return {
      ruleForm2: {
        pass: '',
        checkAccount: ''
      },
      rules2: {
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        checkAccount: [
          { validator: validatePass2, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 请求接口
          this.$axios.get('/api/login').then((res) => {
            console.log('我是登录', res)
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style>
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  background: url(http://pic1.win4000.com/wallpaper/a/556c2226c6f1e.jpg);
  width: 100%;
  height: 100%;
  background-size: 100%;
}
.login-wrap {
  width: 300px;
  height: auto;
  margin: 0 auto;
  background: #695a3854;
  padding: 30px;
}
h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #fff;
}
.el-form-item__label {
  color: #fff;
}
</style>
